package com.zgc.view.controller;

import com.fx.spring.annotation.ControllerFX;
import com.fx.spring.controller.AbstractController;
import com.zgc.view.common.AlertCtrl;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

@ControllerFX(fxmlURL = "/view/fxml/RootBorder.fxml")
public class RootBorderCtrl extends AbstractController<BorderPane> {

    @FXML
    private SplitPane centerSplitPane;
    @FXML
    private BorderPane borderPane;

    @Autowired
    private AlertCtrl alertCtrl;
    @Autowired
    public NewConnectionCtrl connectionCtrl;

    @Autowired
    private InformationTableCtrl informationTableCtrl;

    @Autowired
    private ConnectListViewCtrl connectListViewCtrl;

    /** 初始化 */
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        logger.debug("[{}]初始化完成", location);
        initSplitPane();
    }


    @FXML
    private void newConnect(ActionEvent actionEvent) {
        connectionCtrl.showNewConnectionAlert();
    }

    @FXML
    private void importZkInfo(ActionEvent actionEvent) {
        alertCtrl.setMessageAndShow("导入配置(待开发)");
    }

    @FXML
    private void exportZkInfo(ActionEvent actionEvent) {
        alertCtrl.setMessageAndShow("导出配置(待开发)");
    }

    @FXML
    private void settingZkUI(ActionEvent actionEvent) {
        alertCtrl.setMessageAndShow("设置(待开发)");
    }

    private void initSplitPane() {
        ObservableList<Node> items = centerSplitPane.getItems();
        Platform.runLater(() -> items.add(0, connectListViewCtrl.load()));
        Platform.runLater(() -> items.add(1, informationTableCtrl.load()));

        centerSplitPane.setDividerPosition(0, 0.2);
    }


}

